import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/utils/app_update.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/utils/toast_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/dialog/dialog_util.dart';
import 'package:library_base/widget/image/circle_image.dart';
import 'package:package_info/package_info.dart';
import 'package:flutter/material.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:module_set_up/page/set_up/set_up_controller.dart';

class SetUpPage extends StatefulWidget {
  const SetUpPage({Key? key}) : super(key: key);

  @override
  _SetUpPageState createState() => _SetUpPageState();
}

class _SetUpPageState extends BaseState<SetUpPage, SetUpController> {
  PackageInfo _packageInfo = PackageInfo(
    appName: 'Unknown',
    packageName: 'Unknown',
    version: 'Unknown',
    buildNumber: 'Unknown',
  );

  Future<void> _initPackageInfo() async {
    final PackageInfo info = await PackageInfo.fromPlatform();
    setState(() {
      _packageInfo = info;
    });
  }

  @override
  SetUpController registerController() => Get.find<SetUpController>();

  @override
  void onCreate() {
    _initPackageInfo();
    setBackgroundColor(ThemeUtil.getTheme().secondaryBgColor());
    setTitleVisible(true);
    setTitle(MultiLanguage.setUp.tr);
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          Container(
            color: ThemeUtil.getTheme().colorScheme.secondary,
            alignment: Alignment.centerLeft,
            width: double.infinity,
            padding: edgeV40H24,
            child: Row(
              children: [
                CircleImage(
                  Constant.placeholderImg,
                  radius: 64.r,
                  borderColor: ThemeUtil.getTheme().colorScheme.secondary,
                ),
                gapW25,
                Expanded(
                    child: Text(SPUtil.nickname,
                        style: TextStyles.textBlack36, overflow: TextOverflow.ellipsis)),
              ],
            ),
          ),
          gapH18,
          GradientButton(
            ThemeUtil.getTheme(),
            decoration: BoxDecoration(
                borderRadius: const BorderRadius.only(),
                color: ThemeUtil.getTheme().colorScheme.secondary),
            padding: edgeV36H24 as EdgeInsets,
            textStyle: transparentTextColor26,
            normalColor: ThemeUtil.getTheme().colorScheme.secondary,
            normalTextColor: ThemeUtil.getTheme().normalTextColor(),
            child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                child: Row(
                  children: [
                    Expanded(child: Text(MultiLanguage.accountInformation.tr)),
                    LocalImage('grey_rightward_arrow',
                        package: Constant.setUpIsRun.packSetUp(),
                        width: 15.27.w,
                        height: 26.76.h,
                        fit: BoxFit.fitWidth),
                  ],
                )),
            onPressed: () {
              // ThemeUtil.changeTheme(ThemeType.dark);
              // Get.updateLocale(const Locale("en", "US"));
              ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
            },
          ),
          line3,
          GradientButton(
            ThemeUtil.getTheme(),
            decoration: BoxDecoration(
                borderRadius: const BorderRadius.only(),
                color: ThemeUtil.getTheme().colorScheme.secondary),
            padding: edgeV36H24 as EdgeInsets,
            textStyle: transparentTextColor26,
            normalColor: ThemeUtil.getTheme().colorScheme.secondary,
            normalTextColor: ThemeUtil.getTheme().normalTextColor(),
            child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                child: Row(
                  children: [
                    Expanded(child: Text(MultiLanguage.languageChange.tr)),
                    LocalImage('grey_rightward_arrow',
                        package: Constant.setUpIsRun.packSetUp(),
                        width: 15.27.w,
                        height: 26.76.h,
                        fit: BoxFit.fitWidth),
                  ],
                )),
            onPressed: () {
              // Get.updateLocale(const Locale("zh", "CN"));
              // Get.updateLocale(const Locale("en", "US"));
              ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
            },
          ),
          line3,
          GradientButton(
            ThemeUtil.getTheme(),
            decoration: BoxDecoration(
                borderRadius: const BorderRadius.only(),
                color: ThemeUtil.getTheme().colorScheme.secondary),
            padding: edgeV36H24 as EdgeInsets,
            textStyle: transparentTextColor26,
            normalColor: ThemeUtil.getTheme().colorScheme.secondary,
            normalTextColor: ThemeUtil.getTheme().normalTextColor(),
            child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                child: Row(
                  children: [
                    Expanded(child: Text(MultiLanguage.themeColor.tr)),
                    LocalImage('grey_rightward_arrow',
                        package: Constant.setUpIsRun.packSetUp(),
                        width: 15.27.w,
                        height: 26.76.h,
                        fit: BoxFit.fitWidth),
                  ],
                )),
            onPressed: () {
              ToastUtil.normal(MultiLanguage.featureNotYetAvailable.tr);
            },
          ),
          line3,
          GradientButton(
            ThemeUtil.getTheme(),
            decoration: BoxDecoration(
                borderRadius: const BorderRadius.only(),
                color: ThemeUtil.getTheme().colorScheme.secondary),
            padding: edgeV36H24 as EdgeInsets,
            textStyle: transparentTextColor26,
            normalColor: ThemeUtil.getTheme().colorScheme.secondary,
            normalTextColor: ThemeUtil.getTheme().normalTextColor(),
            child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                child: Row(
                  children: [
                    Expanded(child: Text(MultiLanguage.settingWeighing.tr)),
                    LocalImage('grey_rightward_arrow',
                        package: Constant.setUpIsRun.packSetUp(),
                        width: 15.27.w,
                        height: 26.76.h,
                        fit: BoxFit.fitWidth),
                  ],
                )),
            onPressed: () {
                Get.toNamed(Routers.settingWeighingPage);
            },
          ),
          line3,
          GradientButton(
            ThemeUtil.getTheme(),
            decoration: BoxDecoration(
                borderRadius: const BorderRadius.only(),
                color: ThemeUtil.getTheme().colorScheme.secondary),
            padding: edgeV36H24 as EdgeInsets,
            textStyle: transparentTextColor26,
            normalColor: ThemeUtil.getTheme().colorScheme.secondary,
            normalTextColor: ThemeUtil.getTheme().normalTextColor(),
            child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                child: Row(
                  children: [
                    Expanded(child: Text(MultiLanguage.checkForUpdates.tr)),
                    Text('${MultiLanguage.currentVersion.tr}${_packageInfo.version}_${Constant.envStr}'),
                    gapH18,
                    LocalImage('grey_rightward_arrow',
                        package: Constant.setUpIsRun.packSetUp(),
                        width: 15.27.w,
                        height: 26.76.h,
                        fit: BoxFit.fitWidth),
                  ],
                )),
            onPressed: () {
              initXUpdate(isShowToast: true);
            },
          ),
          gapH18,
          GradientButton(
            ThemeUtil.getTheme(),
            decoration: BoxDecoration(
                borderRadius: const BorderRadius.only(),
                color: ThemeUtil.getTheme().colorScheme.secondary),
            padding: edgeV36H24 as EdgeInsets,
            textStyle: transparentTextColor26,
            normalColor: ThemeUtil.getTheme().colorScheme.secondary,
            normalTextColor: ThemeUtil.getTheme().normalTextColor(),
            child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                child: Text(MultiLanguage.signOut.tr, style: transparentTextColor30)),
            onPressed: () {
              DialogUtil.showCupertinoAlertDialog(context,
                  title: MultiLanguage.signOut.tr,
                  content: MultiLanguage.areYouSureYouWantToLogOut.tr,
                  cancel: MultiLanguage.cancel.tr,
                  confirm: MultiLanguage.determine.tr,
                  cancelPressed: () => Get.back(),
                  confirmPressed: () async {
                    SPUtil.clear();
                    Get.offAllNamed(Routers.login);
                  });
            },
          ),
        ],
      ),
    );
  }
}
